#ifndef CSSDECODER_H
#define CSSDECODER_H
#include "widget_encoder.h"
#include <vector>
#include <unordered_map>
#include <functional>
#include "widget_codec_global.h"
namespace dymy
{
    class WIDGET_CODEC_EXPORT CSSDecoder
    {
        typedef std::unordered_map<std::string, std::string> Styles;

    private:
        float scale_;
        const char *kCSSSplit = "\n";
        const char *kCSSAttrSplit = ": ";

    public:
        explicit CSSDecoder(float scale);

        Widget *Decode(const std::string &code) const;

        std::optional<float> px_to_dp(const std::string &px_text) const noexcept;

        bool contains_attr(const Styles &styles, const std::string &attr) const
        {
            return styles.find(attr) != styles.cend();
        }

        std::optional<EdgeInsets> parse_edge_insets(const std::string &s) const noexcept;

        std::optional<Container::Border> parseBorder(const std::string &s) const;

    private:
        Text *Styles2Text(const Styles &styles) const;
        Container *Styles2Container(const Styles &styles) const;
    };
}
#endif // CSSDECODER_H
